package priv.bruce.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import priv.bruce.entry.MoviePicture;
import priv.bruce.util.HandlerSet;
import priv.bruce.util.JDBCUtil;

public class MoviePictureService {
	public List<MoviePicture> findById(int Id) throws Exception{
		String sql="select * from t_picture where movie_id=? ";
		return JDBCUtil.query(sql,  new HandlerSet<MoviePicture>(){
			@Override
			public MoviePicture handler(ResultSet rs) throws SQLException {
				MoviePicture moviePicture = new MoviePicture();
				moviePicture.setPicture_id(rs.getInt("picture_id"));
				moviePicture.setMovie_id(rs.getInt("movie_id"));
				moviePicture.setPicture_path(rs.getString("picture_path"));
				return moviePicture;
			}
		}, Id);
	}
	
	public int addPicture(int id , String path) throws Exception {
		String sql = "insert into t_picture(movie_id,picture_path) values(?,?)";
		return JDBCUtil.update(sql, id , path);
	}
}
